﻿@using CoralNode.Core.Entity.Domains.Prototype
@using CoralNode.MvcClient.Helper
@using Coralcode.Base.Entity
@using Coralcode.Base.Utils
@using CoralNode.Core.Entity.Domains.Node
@using CoralNode.Core.Entity.Enums
@model CoralNode.Core.Entity.SearchQuerys.Node.NodeSearchQuery
@{
    ViewData["curr"] = "prototype";
    IList<ProtoypeFieldCustomDomain> customFieldList = ViewBag.CustomFieldList;
}
<!--left-->
@Html.IncludePage("CoralAdmin/Node", "_Left")
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_system"></span><span class="t t_c">
                内容管理&nbsp;&nbsp;/&nbsp;&nbsp;<b class=" t_small f_no">原型分类视图</b>
            </span>
        </div>
        <div id="main">
            <div class="line_solid clearfix">
                @Html.IncludePage("CoralAdmin/Node", "_Side", new { url = "/m/node/listnode?categoryId=" })
                <div class="ml_12">
                    <div class="">
                        <div class="tablelist_style1" data-js="tabellist_style1">
                            <div class="funsearch p_1 pl_2 pr_2">
                                @if (ViewBag.Category != null || ViewBag.PrototypeId != 0) {
                                    <a class="btn_5 f_r ml_3" href="/m/node/createNode?categoryId=@(ViewBag.Category == null ? 0 : ViewBag.Category.Id)&prototypeId=@ViewBag.PrototypeId">
                                        添加内容
                                    </a>
                                    <a class="btn_5 f_r ml_3 j_export" href="/m/node/export?id=@ViewBag.PrototypeId" target="_blank">
                                        导出内容
                                    </a>
                                }
                                <div class="f_r">
                                    <form class="j_ajax" method="POST" action="/m/node/listNode">
                                        @Html.Hidden("PrototypeId", Model.PrototypeId)
                                        @*<span class="t_des f_l pt_0-5">原型：</span>

                                            <div class="select_owner w_12 mr_1" data-meta="{value:'@Model.PrototypeId',name:'PrototypeId', btn:'<span class=\'ico ico_slide_down\'></span>' , clickbtn:'<span class=\'ico ico_slide_up\'></span>'}">
                                                <ul>
                                                     <li data-value="0">全部</li>
                                                    @foreach (var item in @ViewBag.PrototypeList) {
                                                        <li data-value="@item.Id">@item.Title</li>
                                                    }
                                                </ul>
                                            </div>*@
                                        @* <span class="t_des f_l pt_0-5">状态：</span>
                                            <div class="select_owner w_10 mr_1 " data-meta="{value:'@Model.Status',name:'Status', btn:'<span class=\'ico ico_slide_down\'></span>' , clickbtn:'<span class=\'ico ico_slide_up\'></span>'}">
                                                 <ul>
                                                     <li data-value="0">全部</li>
                                                      @foreach (var item in @ViewBag.StatusList) {
                                                         <li data-value="@item.Value">@item.Key</li>
                                                      }
                                                 </ul>
                                             </div>*@
                                        <span class="t_des f_l pt_0-5">内容名称</span>
                                        <label class="search f_l">
                                            @Html.TextBoxFor(m => m.Title, new { @class = "text w_18", @msg = "请输入关键字" })
                                            @Html.HiddenFor(m=>m.CategoryId)
                                            @Html.AntiForgeryToken()
                                            <input type="submit" value="" class="submit" />
                                        </label>
                                    </form>
                                </div>

                            </div>
                            @if (customFieldList.Count > 0) {
                                <table cellpadding="0" cellspacing="0" class="mt_3-5">
                                    <tr class="exclude">
                                        <th width="60">选择</th>
                                        @foreach (var item in customFieldList) {
                                            <th align="left">@item.Title</th>
                                        }
                                        <th>创建时间</th>
                                        <th width="60">状态</th>
                                        <th width="140">操作</th>
                                    </tr>
                                    @foreach (NodeDomain item in @ViewBag.NodeList.Items) {
                                        <tr data-depth="0">
                                            <td>
                                                <label class="checkbox_own">
                                                    <input type="checkbox" value="@item.Id" />
                                                </label>
                                            </td>
                                            @foreach (var custom in customFieldList) {
                                                <td class="td_left">@ManageHtmlHelper.Reflect(ViewBag.NodeFieldValues, item, custom)</td>
                                            }
                                            <td>@ShowTime(item.CreateTime) @EnumUtil.GetEnumValue(NodeEnums.NodeStatus, item.Status)</td>
                                            <td>
                                                <a href="/m/node/ChangeNodeStatus/@item.Id" title="@EnumUtil.GetEnumDescription(NodeEnums.NodeStatus, item.Status)" class="ico ico_eye_@item.Status js_changestate btn">
                                                </a>
                                            </td>
                                            <td>
                                                <div class="fun">
                                                    <a href="/m/node/editNode/@item.Id?categoryId=@item.CategoryId&prototypeId=@ViewBag.PrototypeId">
                                                        编辑
                                                    </a><a href="/m/node/deleteNode/@item.Id" class="js_delete">删除</a>@*<a href="/m/node/ListRelNode?nodeId=@item.Id" rel="#overlay">关联</a>*@
                                                </div>
                                            </td>
                                        </tr>
                                    }
                                </table>
                            } else {
                                <table cellpadding="0" cellspacing="0" class="mt_3-5">
                                    <tr class="exclude">
                                        <th width="60">选择</th>
                                        <th width="100" align="left">ID</th>
                                        <th align="left">标题</th>
                                        <th>创建时间</th>
                                        <th>排序</th>
                                        <th width="60">状态</th>
                                        <th width="140">操作</th>
                                    </tr>
                                    @helper ShowTime(DateTime time) {
                                        DateTime now = DateTime.Now;
                                        if (now.Year - time.Year == 0) {
                                            @time.ToString("MM-dd HH:mm")
                                            ;
                                        } else {
                                            @time.ToString("yyyy-MM-dd HH:mm")
                                            ;
                                        }

}
                                    @foreach (NodeDomain item in @ViewBag.NodeList.Items) {
                                        <tr data-depth="0">
                                            <td>
                                                <label class="checkbox_own">
                                                    <input type="checkbox" value="@item.Id" />
                                                </label>
                                            </td>
                                            <td class="td_left">@item.Id</td>
                                            <td class="td_left">
                                                <a href="/m/node/editNode/@item.Id?categoryId=@item.CategoryId">@item.Title</a>
                                            </td>
                                            <td>@ShowTime(item.CreateTime)</td>
                                            <td>
                                                <a href="/m/node/ChangeRank/@item.Id" class="ico ico_moveup mr_2 f_no  btn"></a><a href="/m/node/ChangeRank/@item.Id" class="ico ico_movedown btn"></a>
                                            </td>
                                            <td>
                                                <a href="/m/node/ChangeNodeStatus/@item.Id" title="@EnumUtil.GetEnumDescription(NodeEnums.NodeStatus,item.Status)" class="ico ico_eye_@item.Status js_changestate btn">
                                                </a>
                                            </td>
                                            <td>
                                                <div class="fun">
                                                    <a href="/m/node/editNode/@item.Id?categoryId=@item.CategoryId&prototypeId=@ViewBag.PrototypeId">
                                                        编辑
                                                    </a><a href="/m/node/deleteNode/@item.Id" class="js_delete">删除</a>@*<a href="/m/node/ListRelNode?nodeId=@item.Id" rel="#overlay">关联</a>*@
                                                </div>
                                            </td>
                                        </tr>
                                    }
                                </table>
                            }
                            <div class="global_fun ">
                                <label class="checkbox_own gloabal_select">
                                    <input type="checkbox" />
                                </label>
                                <input type="button" class="btn_4 btn invert" value="反选" /><input type="button" class="btn_4 btn reset"
                                                                                                  value="重置" />
                                <a href="/m/node/DelBatchNode" class="js_delete">删除</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="pager">
                    <div class="info_pg">共@(ViewBag.NodeList.TotalItems)条</div>
                    <div class="list_pg">
                        <a href="/m/node/listNode?@ViewBag.queryString&p=1" class="first">首页</a>
                        @if (@ViewBag.NodeList.HasPreviousPage && @ViewBag.NodeList.TotalItems > 0) {
                            <a href="/m/node/listNode?@ViewBag.queryString&p=@ViewBag.NodeList.PreviousPageIndex" class="prev">
                                上一页
                            </a>
                        } else {
                            <a class="prev none">上一页</a>
                        }
                        @foreach (var i in @ViewBag.NodeList.PageArray) {
                            if (@i == @ViewBag.NodeList.CurrentPageIndex) {
                                <a class="current">@i</a>
                            } else if (@i == 0) {
                                <a class="more">…</a>
                            } else {
                                <a href="/m/node/listNode?@ViewBag.queryString&p=@i" href="#">@i</a>
                            }
                        }
                        @if (@ViewBag.NodeList.HasNextPage && @ViewBag.NodeList.TotalItems > 0) {
                            <a class="next" href="/m/node/listNode?@ViewBag.queryString&p=@ViewBag.NodeList.NextPageIndex">
                                下一页
                            </a>
                        } else {
                            <a class="next none">下一页</a>
                        }
                        <a class="last" href="/m/node/listNode?@ViewBag.queryString&p=@ViewBag.NodeList.TotalPages">
                            尾页
                        </a>
                        <!-- <span class="msg">跳转</span>
                        <input class="text" type="text" value="">
                        <span class="msg">页</span>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="overlay" class="clearfix overlay w_90">
    <div class="js-overlay-node"></div>
</div>

<script>
    $(document).ready(function () {
        $("a[rel]").overlay({
            mask: {
                color: '#000',
                opacity: 0.6
            },
            closeOnClick: false,
            fixed: false,
            left: 'center',
            top: 'center',
            onBeforeLoad: function () {
                $('.js-overlay-node').load(this.getTrigger().attr("href"));
            }
        });

        $('.js-overlay_close').live("click", function () {
            $('.close').trigger("click");
        });
        $('.j_export').click(function () {
            var href = $(this).attr("href");
            var $elements = $(this).parents("[data-js='tabellist_style1']").find("td .checkbox_own input[type='checkbox']:checked");
            var ids = new Array();
            $elements.each(function () {
                ids.push($(this).val());
            });
            $(this).attr("href", href + "&idstring=" + ids);
        });
    });
</script>
